<?php
    $this->headTitle('Resource','append');
    $mResource = new Admin_Model_Resource();
?>
<div class="row-fluid page-head">
    <h2 class="page-title"><i class="fontello-icon-monitor"></i> Resource <small>Notice</small></h2>
    <p class="pagedesc">Description</p>
    <div class="page-bar">
        <div class="btn-toolbar"> </div>
    </div>
</div>
<!-- // page head -->

<div id="page-content" class="page-content">
    <nav>
        <ul class="btn-toolbar page-nav margin-btn">                        
            <?php if($this->acl->checkAllowed(array('moduleName'=>'admin','controllerName'=>'resource','actionName'=>'add'))){ ?>
                <li>
                    <a class="btn btn-well btn-glyph" href="<?php echo $this->url(array('module'=>'admin', 'controller'=>'resource', 'action'=>'add'))?>" style="width:80px">
                        <i class="fontello-icon-plus f30"></i>
                        <span class="block">Thêm</span>
                    </a>
                </li>
            <?php } ?>                                                 
        </ul>
        <hr class="margin-0x"/>
    </nav>
    <section>
        <div class="row-fluid margin-bottom16">
            <div class="span12">            
                <div class="tabbable tabbable-bordered tabs-top">
                    <ul class="_hidden nav nav-tabs">
                        <li class="active"><a href="#tabResourceAdmin" data-toggle="tab">Chức năng quản trị</a></li>
                        <li class=""><a href="#tabResourceDefault" data-toggle="tab">Chức năng người dùng</a></li>                    
                    </ul>                    
                    <div class="tab-content" style="min-height:150px">
                        <div class="tab-pane active" id="tabResourceAdmin">
                            <div class="widget widget-simple widget-table">
                                <div class="widget-header">                                    
                                    <div class="span12">                                        
                                        <div class="pull-right">
                                            <div class="btn-group">
                                                <a class="btn btn-green" onclick="fResourceTableDisplay('resourceAdminFunc','admin')" title="Nhóm Resource theo Controller" data="resourceAdminFunc">Group by Func</a>                                            
                                                <a class="btn" onclick="fResourceTableDisplay('resourceAdminMenu','admin')" title="Nhóm Resource theo Menu" data="resourceAdminMenu">Group by Menu</a>
                                            </div>
                                        </div>                                        
                                    </div>
                                </div>
                                <table id="table-resource" class="table boo-table table-striped table-content table-hover dataTable" data="resourceAdminFunc">
                                    <thead>
                                        <tr>                                
                                            <th scope="col">Name <span class="column-sorter"></span></th>                                            
                                            <th scope="col">Controller <span class="column-sorter"></span></th>
                                            <th scope="col">Action <span class="column-sorter"></span></th>
                                            <th scope="col">Menu Group <span class="column-sorter"></span></th>                                            
                                            <th scope="col">Display <span class="column-sorter"></span></th>
                                            <th scope="col">Func <span class="column-sorter"></span></th>                                
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php                            
                                            foreach ($this->adCtrlResourceList as $resource){
                                                $temp = $mResource->getData(array('moduleName'=>'admin','controllerName'=>$resource));
                                                $i=0;
                                                foreach($temp as $re){$i++;
                                        ?>
                                                    <tr>                                    
                                                        <td><?php echo $re['resourceName'];?></td>
                                                        <?php
                                                        	if($i==1){
                                                        	   echo '<td style="text-align:center;vertical-align:middle" rowspan="'.$temp->count().'">'.strtoupper($re['controllerName']).'</td>';
                                                        	}
                                                        ?>                                                                                                        
                                                        <td><?php echo strtoupper($re['actionName']);?></td>                                    
                                                        <td><?php echo $re['menuName'];?></td>                                                        
                                                        <td>
                                                            <?php
                                                                if($re['displayTemplate'] == 1)
                                                                    echo '<a class="btn btn-mini btn-glyph btn-green" onclick="displayResource('.$re['resourceId'].')"><i class="fontello-icon-ok-2"></i></a>';
                                                                else
                                                                    echo '<a class="btn btn-mini btn-glyph btn-red" onclick="displayResource('.$re['resourceId'].')"><i class="fontello-icon-cancel-2"></i></a>';                                                        
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <?php if($this->acl->checkAllowed(array('moduleName'=>'admin','controllerName'=>'resource','actionName'=>'edit'))){ ?>                                    
                                                                <a class="btn btn-mini btn-glyph btn-yellow" href="<?=$this->url(array('module'=>'admin', 'controller'=>'resource', 'action'=>'edit', 'resourceId'=>$re['resourceId']))?>"><i class="fontello-icon-edit-2"></i></a>
                                                            <?php } ?>
                                                            &nbsp;&nbsp;
                                                            <?php if($this->acl->checkAllowed(array('moduleName'=>'admin','controllerName'=>'resource','actionName'=>'delete'))){ ?>                                    
                                                                <a class="btn btn-mini btn-glyph btn-red" href="<?=$this->url(array('module'=>'admin', 'controller'=>'resource', 'action'=>'delete', 'resourceId'=>$re['resourceId']))?>"><i class="fontello-icon-trash-2"></i></a>
                                                            <?php } ?>
                                                        </td>
                                                    </tr>                                                                                                                
                                        <?php
                                                }
                                        	}
                                        ?>
                                    </tbody>
                                </table>
                                <!-- // DATATABLE FUNC -->
                                <table id="table-resource" class="table boo-table table-striped table-content table-hover dataTable" data="resourceAdminMenu" style="display:none">
                                    <thead>
                                        <tr>                                
                                            <th scope="col">Name <span class="column-sorter"></span></th>
                                            <th scope="col">Menu Group <span class="column-sorter"></span></th>                                            
                                            <th scope="col">Controller <span class="column-sorter"></span></th>
                                            <th scope="col">Action <span class="column-sorter"></span></th>                                            
                                            <th scope="col">Order <span class="column-sorter"></span></th>
                                            <th scope="col">Display <span class="column-sorter"></span></th>
                                            <th scope="col">Func <span class="column-sorter"></span></th>                                
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php                       
                                            //pr($this->adMenuResourceList);     
                                            foreach ($this->adMenuResourceList as $resource){
                                                $temp = $mResource->getData(array('moduleName'=>'admin','menuModel'=>$resource));
                                                $i=0;
                                                foreach($temp as $re){$i++;
                                        ?>
                                            <tr>                                    
                                                <td><?php echo $re['resourceName'];?></td>                                                
                                                <?php
                                                	if($i==1){
                                                	   echo '<td style="text-align:center;vertical-align:middle" rowspan="'.$temp->count().'">'.$re['menuName'].'</td>';
                                                	}
                                                ?>                                                                                                
                                                <td><?php echo strtoupper($re['controllerName']);?></td>
                                                <td><?php echo strtoupper($re['actionName']);?></td>                                                                                    
                                                <td act='editable' data='<?php echo $re['resourceId']?>'>
                                                    <label style="display: inline;"><?php echo $re['ord'];?></label>
                                                    <a class="btn btn-mini btn-glyph btn-blue" data="<?php echo $re['resourceId'];?>" act="edit"><i class="fontello-icon-edit"></i></a>
                                                </td>
                                                <td act='edit-detail' data='<?php echo $re['resourceId']?>'>
                                                    <input type="text" class="span2" style="margin-bottom:0px;" act="input"/>
                                                    <a class="btn btn-mini btn-glyph btn-green" onclick="" act="save"><i class="fontello-icon-ok-circle"></i></a>
                                                    <a class="btn btn-mini btn-glyph btn-red" onclick="" act="cancel"><i class="fontello-icon-cancel-circle"></i></a>
                                                </td>
                                                <td>
                                                    <?php
                                                        if($re['displayTemplate'] == 1)
                                                            echo '<a class="btn btn-mini btn-glyph btn-green" onclick="displayResource('.$re['resourceId'].')"><i class="fontello-icon-ok-2"></i></a>';
                                                        else
                                                            echo '<a class="btn btn-mini btn-glyph btn-red" onclick="displayResource('.$re['resourceId'].')"><i class="fontello-icon-cancel-2"></i></a>';                                                        
                                                    ?>
                                                </td>
                                                <td>
                                                    <?php if($this->acl->checkAllowed(array('moduleName'=>'admin','controllerName'=>'resource','actionName'=>'edit'))){ ?>                                    
                                                        <a class="btn btn-mini btn-glyph btn-yellow" href="<?=$this->url(array('module'=>'admin', 'controller'=>'resource', 'action'=>'edit', 'resourceId'=>$re['resourceId']))?>"><i class="fontello-icon-edit-2"></i></a>
                                                    <?php } ?>
                                                    &nbsp;&nbsp;
                                                    <?php if($this->acl->checkAllowed(array('moduleName'=>'admin','controllerName'=>'resource','actionName'=>'delete'))){ ?>                                    
                                                        <a class="btn btn-mini btn-glyph btn-red" href="<?=$this->url(array('module'=>'admin', 'controller'=>'resource', 'action'=>'delete', 'resourceId'=>$re['resourceId']))?>"><i class="fontello-icon-trash-2"></i></a>
                                                    <?php } ?>
                                                </td>
                                            </tr>                            
                                         <?php
                                                }
                                        	}
                                        ?>
                                    </tbody>
                                </table>
                                <!-- // DATATABLE MENU -->
                            </div>
                        </div>
                        <!-- // tab1 -->
                        
                        <div class="tab-pane" id="tabResourceDefault">
                            
                        </div>
                        <!-- // tab2 -->                                                                            
                    </div>
                </div>                                        
            </div>
        </div>                            
    </section>    
</div>
<!-- // page content -->